package shiyan2;

import java.io.*;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class shiyan2_3_cli {
    public static void main(String[] args) throws IOException {
        Socket sock = new Socket("localhost",8888);
        try(InputStream input = sock.getInputStream()) {
            try(OutputStream output = sock.getOutputStream()){
                var writer = new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8));
                var reader = new BufferedReader(new InputStreamReader(input,StandardCharsets.UTF_8));
                Scanner scan = new Scanner(System.in);
                String userinput;
                String outputstr;
                while (true){
                    userinput = scan.nextLine();
                    writer.write(userinput+"\n");
                    writer.flush();
                    outputstr = reader.readLine();
                    System.out.println(outputstr);
                }
            }
        }catch (Exception e){
                sock.close();
        }
        sock.close();
    }
}
